<?php
//require_once 'dr-app-config.php';
//echo '<pre>';

function dr_db_get_all_pages_without_content()
{
	global $db;

	$sql = 'SELECT `page_id`,`title`,`position` FROM `^pages` ORDER BY `position` ASC';
	$result = dr_db_query_sub($db, $sql);

	$pages = array();
	while ($page = mysql_fetch_assoc($result)) {
		$pages[] = $page;
	}
	return $pages;
}

//var_dump(dr_db_get_all_pages_without_content());

function dr_db_get_page_with_id($page_id)
{
	global $db;

	$sql = 'SELECT * FROM `^pages` WHERE `page_id` = $';
	$result = dr_db_query_sub($db, $sql, $page_id);

	if ($page = mysql_fetch_assoc($result)) {
		return $page;
	}
	return false;
}

function dr_db_add_page($page)
{
	global $db;

	$sql = 'INSERT INTO `^pages` (`title`, `content`, `position`) VALUES ($, $, $) ON DUPLICATE KEY UPDATE `title` = VALUES(`title`), `content` = VALUES(`content`), `position` = VALUES(`position`)';
	$result = dr_db_query_sub($db, $sql, $page['title'], $page['content'], $page['position']);

	if ($result) {
		return true;
	}
	return false;
}

function dr_db_update_page($page)
{
	global $db;

	$sql = 'UPDATE `^pages` SET `title` = $, `content` = $, `position` = $ WHERE `page_id` = $';
	$result = dr_db_query_sub($db, $sql, $page['title'], $page['content'], $page['position'], $page['page_id']);
	return $result;
}
